﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using GBIT.Web;
using System.Linq;
using System.Linq.Expressions;
using WebComponents;
using WebComponents.Data;
using WebComponents.Security;

public partial class ThemSupportOnline : UserControlBase {
  public int id = 0;
  protected void Page_Load(object sender, EventArgs e) {
    id = ToInt(Request.Params["id"]);
    this.Title = "Thông tin support";
    this.TaskTitle = "Thêm mới";
    if (!Page.IsPostBack) {
      if (id > 0) {
        SuportOnlineInfo s = SuportOnlineController.GetByID(id);
        if (s != null) {
          txtTitle.Text = s.Description;
          txtTitleEn.Text = s.DescriptionEn;
          txtNickName.Text = s.YM;
          txtOrderId.Text = s.OrderId.ToString();
          if (cmbNickType.Items.FindByValue(s.NickType) != null) {
            cmbNickType.SelectedIndex = -1;
            cmbNickType.Items.FindByValue(s.NickType).Selected = true;
          }
          if (s.Status == 1)
            chkActive.Checked = true;
          else
            chkActive.Checked = false;
          this.TaskTitle = "Cập nhật";
        }
      }
    }
    this.SaveEnabled = true;    
  }
  protected override void OnSaveRecord(bool redirect) {
    SuportOnlineInfo s = null;
    if (id > 0)
      s = SuportOnlineController.GetByID(id);
    if (s == null)
      s = new SuportOnlineInfo();
    s.Description = txtTitle.Text;
    s.DescriptionEn = txtTitleEn.Text;
    s.YM = txtNickName.Text.Trim();
    s.OrderId = ToInt(txtOrderId.Text);
    s.NickType = cmbNickType.SelectedValue;
    s.Status = (chkActive.Checked) ? 1 : 0;
    if (id <= 0) {
      SuportOnlineController.Insert(s);
      Security.ShowClientMessage(Page, "Thêm thông tin support thành công", "?tabid=1&cid=24");
    } else {
      SuportOnlineController.Update(s);
      Security.ShowClientMessage(Page, "Cập nhật thông tin support thành công", "?tabid=1&cid=24");
    }
  }
}
